package gui.swing;

import javax.swing.*;
import java.awt.*;
import java.net.URL;

public class ImageIconDemo extends JFrame {

    public ImageIconDemo(){
        //获取图片地址
        JLabel jLabel = new JLabel("ImageIcon");
        URL url = ImageIconDemo.class.getResource("zsh.jpg");
//        String url = "E:\\new PC\\study\\java学习\\code\\JavaSE\\基础语法\\src\\gui\\swing\\zsh.jpg";
        System.out.println(url);

        ImageIcon imageIcon = new ImageIcon(url);

        jLabel.setIcon(imageIcon);
        jLabel.setHorizontalAlignment(SwingConstants.CENTER);

        Container contentPane = getContentPane();
        contentPane.add(jLabel);
        setVisible(true);
        setBounds(100,100,400,400);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

    }

    public static void main(String[] args) {
        new ImageIconDemo();
    }
}
